package five8.d20211009.t3;

/**
 * @author habitplus
 * @since 2021-10-09 22:41
 */
public class Main {
    public int StringSplit(String str) {
        if (str == null || str.length() < 2) {
            return 0;
        }

        char[] chs = str.toCharArray();
        int n = chs.length;
        int[] la = new int[n];
        int sum = 0;
        for (int i = 0; i < n - 1; i++) {
            if (chs[i] == 'a') sum++;
            la[i] = sum;
        }

        int rb = 0;
        int max = 0;
        for (int i = n - 1; i > 0; i--) {
            if (chs[i] == 'b') {
                rb++;
            }
            max = Math.max(la[i - 1] + rb, max);
        }

        return max;
    }

}
